# Maintainer: Rafal Brzegowy <rafal.brzegowy@yahoo.com>

_realname=precice
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.1.1
pkgrel=2
pkgdesc='Fully Parallel Library for Multi-Physics Surface Coupling (mingw-w64)'
arch=('any')
depends=("${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
	 "${MINGW_PACKAGE_PREFIX}-eigen3"
	 "${MINGW_PACKAGE_PREFIX}-msmpi")
makedepends=("${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-libxml2"
             "${MINGW_PACKAGE_PREFIX}-eigen3"
	     "${MINGW_PACKAGE_PREFIX}-msmpi"
	     "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cmake")
license=('LGPL')
url='https://www.precice.org'
source=(https://github.com/precice/precice/archive/v${pkgver}.zip)
md5sums=('97145D8423303422A0C020387F0D64CD')

build() {
  #Static Build
  [[ -d "${srcdir}/build-${MINGW_CHOST}-static" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}-static"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}-static" && cd "${srcdir}/build-${MINGW_CHOST}-static"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_CXX_STANDARD_LIBRARIES=-lws2_32 \
      -DBUILD_SHARED_LIBS=OFF \
      -DCMAKE_BUILD_TYPE=Release \
      -DPRECICE_MPICommunication=ON \
      -DPRECICE_PETScMapping=OFF \
      -DPRECICE_PythonActions=OFF \
      ../${_realname}-${pkgver}

  ninja

  #Shared Build
  [[ -d "${srcdir}/build-${MINGW_CHOST}-shared" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}-shared"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}-shared" && cd "${srcdir}/build-${MINGW_CHOST}-shared"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_CXX_STANDARD_LIBRARIES=-lws2_32 \
      -DBUILD_SHARED_LIBS=ON \
      -DCMAKE_BUILD_TYPE=Release \
      -DPRECICE_MPICommunication=ON \
      -DPRECICE_PETScMapping=OFF \
      -DPRECICE_PythonActions=OFF \
      ../${_realname}-${pkgver}

  ninja
}

package() {
  #Static Install
  cd "${srcdir}/build-${MINGW_CHOST}-static"
  DESTDIR=${pkgdir} cmake --build . --target install	

  #Shared Install
  cd "${srcdir}/build-${MINGW_CHOST}-shared"
  DESTDIR=${pkgdir} cmake --build . --target install
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}

# vim: ts=2 sw=2 et:
